package com.carlinfo.stu_ques.demo.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.carlinfo.stu_ques.demo.dao.IDynastyDao;
import com.carlinfo.stu_ques.demo.dao.IKingDao;
import com.carlinfo.stu_ques.demo.dao.impl.DynastyDaoImpl;
import com.carlinfo.stu_ques.demo.dao.impl.KingDaoImpl;
import com.carlinfo.stu_ques.demo.pojo.Dynasty;
import com.carlinfo.stu_ques.demo.pojo.King;
import com.carlinfo.stu_ques.demo.service.IDynastyService;
/**
 * service的实现类，操作DAO
 * @author 90711
 *
 */
public class DynastyServiceImpl implements IDynastyService{
	
	private IDynastyDao dynastyDao = new DynastyDaoImpl();
	
	private IKingDao kingDao = new KingDaoImpl();
	
	/* ================朝代==================== */
	
	/**
	 * 插入一条数据
	 */
	@Override
	public int saveOneDynastyService(Dynasty dynasty) {
		
		return dynastyDao.saveOneDao(dynasty);
	}
	
	/**
	 * 更新一条数据
	 */
	@Override
	public void updateOneDynastyService(Dynasty dynasty) {
		dynastyDao.updateOneDao(dynasty);
	}

	@Override
	public void deleteOneDynastyService(Dynasty dynasty) {
		this.dynastyDao.deleteOneDao(dynasty);
	}

	/**
	 * 查询所有数据
	 */
	@Override
	public List<Dynasty> selectListDynastyService() {
		return this.dynastyDao.selectListDao();
	}
	
	/**
	 * 查询一条数据
	 */
	@Override
	public Dynasty selectOneDynastyService(Map<String, Object> condMap) {
		return dynastyDao.selectOneDao(condMap);
	}
	
	/**
	 * 设置标题头
	 */
	@Override
	public String title() {
		return "id\t名字\t首都\t年龄\t开国时间\t\t创建时间\t\t\t更新时间";
	}
	
	/* ================king==================== */

	/**
	 * 保存一个皇上
	 */
	@Override
	public int saveOneKingService(King king) {
		return this.kingDao.saveOneDao(king);
	}

	/**
	 * 更新一个皇上
	 */
	@Override
	public void updateOneKingService(King king) {
		this.kingDao.updateOneDao(king);
	}

	/**
	 * 删除一个皇上
	 */
	@Override
	public void deleteOneKingService(King king) {
		this.kingDao.deleteOneDao(king);
	}

	/**
	 * 查询所有皇上
	 */
	@Override
	public List<King> selectListKingService() {
		List<King> list = this.kingDao.selectListDao();
		Map<String, Object> map = new HashMap<String, Object>();
		for (King king : list) {
			
			map.put("id", king.getDynastyId());
			Dynasty dynasty = this.selectOneDynastyService(map);
			king.setDynasty(dynasty);
		}
		return list;
	}

	/**
	 * 查询一个皇上
	 */
	@Override
	public King selectOneKingService(Map<String, Object> condMap) {
		return this.kingDao.selectOneDao(condMap);
	}

	@Override
	public String kingTitle() {
		/* id,朝代Id,名字,年龄,身高,庙号,年号,创建时间,更新时间 */
		return "id\t朝代\t名字\t年龄\t身高\t庙号\t年号\t创建时间\t\t\t更新时间";
	}

	@Override
	public boolean dynastyDbTofile(String path)
	{
		return this.dynastyDao.dbToFile(path);
	}

	@Override
	public boolean dynastyFileToDb()
	{
		return this.dynastyDao.fileToDb();
	}

	@Override
	public boolean kingDbTofile(String path)
	{
		return this.kingDao.dbToFile(path);
	}

	@Override
	public boolean kingFileToDb()
	{
		return this.kingDao.fileToDb();
	}
	
	
}